<template>
	<view class="page">
		<view class="info_box">
			<view class="first">
				<image :src="userInfo.avatarUrl || '../../static/user.png'" mode="" class="photo"></image>
				<block v-if="noCode">
					<button class="login_btn" @click="goLogin" v-if="!obj">
						登录/注册
					</button>
				</block>
				<text v-else>{{userInfo.nickName}}</text>
			</view>
		</view>
		<view class="card" v-if="isShop">
			<view class="box">
				<image src="../../static/my_06.png" mode=""></image>
				<text>添加会员</text>
				<view class="btn" @click="goVipRegister">去添加</view>
			</view>
		</view>
		<view class="href_list">
			<view class="item" @click="goOrder">
				<image src="../../static/my_01.png" class="icon" mode="heightFix"></image>我的订单
				<image src="../../static/right.png" mode="" class="right"></image>
			</view>
			<view class="item" @click="goVip" v-if="isShop">
				<image src="../../static/my_07.png" class="icon" mode="heightFix"></image>会员列表
				<image src="../../static/right.png" mode="" class="right"></image>
			</view>
			<view class="item" @click="goCouponList">
				<image src="../../static/my_04.png" class="icon" mode="heightFix"></image>我的优惠券
				<image src="../../static/right.png" mode="" class="right"></image>
			</view>
			<view class="item" @click="goShop" v-if="!isShop">
				<image src="../../static/my_02.png" class="icon" mode="heightFix"></image>入驻商家
				<image src="../../static/right.png" mode="" class="right"></image>
			</view>
			<view class="item" @click="getCode" v-if="!isShop">
				<image src="../../static/my_05.png" class="icon" mode="heightFix"></image>二维码入驻
				<image src="../../static/right.png" mode="" class="right"></image>
			</view>
			<view class="item" @click="siaom" v-if="isShop">
				<image src="../../static/my_03.png" class="icon" mode="heightFix"></image>扫码
				<image src="../../static/right.png" mode="" class="right"></image>
			</view>
		</view>
		<view class="modal" v-if="modalShow" @click="clearLun">
			<image :src="codeSrc" mode=""></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				noCode: true,
				userInfo: {},
				isShop:false,
				codeSrc:"",
				modalShow:false,
				searchShop:"",
			}
		},
		methods: {
			lun(){
				let searchShop = setInterval(()=>{
					this.getUserInfo()
				},1000)
				this.searchShop = searchShop;
			},
			clearLun(){
				clearInterval(this.searchShop);
				this.modalShow = false;
			},
			goCouponList(){
				uni.navigateTo({
					url: `/pages/index/index`
				})
			},
			goLogin(){
				uni.navigateTo({
					url: "/pages/my/login"
				})
			},
			goVipRegister(){
				uni.navigateTo({
					url: "/pages/my/vipRegister"
				})
			},
			siaom() {
				uni.scanCode({
					onlyFromCamera: true,
					success: (res) => {
						var data = res.result;
						this.$get('shop/shopmemberverification', {
							str: data
						}, (res) => {
							uni.showToast({
								title: "核销成功！",
								icon: "none"
							});
						})
						console.log("扫码成功")
						console.log(res)
					},
					fail: (res) => {
						console.log(res)
					},
				})
			},
			getUserInfo() {
				this.$get('user/index', {}, (res) => {
					this.isShop = !!res.is_shop
					if(this.isShop){
						this.clearLun()
					}
					console.log(res)
				})
			},
			getToken() {
				this.$get('user/login', {
					account: "admin",
					password: "123456"
				}, (res) => {
					console.log(res)
				})
			},
			goOrder() {
				uni.switchTab({
					url: '/pages/appointment/appointment'
				});
			},
			goShop() {
				uni.navigateTo({
					url: "/pages/shop/beShop"
				})
			},
			goVip() {
				uni.navigateTo({
					url: "/pages/my/vipList"
				})
			},
			getCode(){
				if(this.codeSrc){
					this.modalShow = true;
					this.lun()
					return
				}
				this.$getS('user/showaddshopqrcord', {
				}, (res) => {
					this.codeSrc = res
					this.modalShow = true;
					this.lun()
				})
			}
		},
		onLoad() {
			// uni.setStorageSync('token', "2e1ab733-3e9f-49f5-873c-1faecc0100e6");
			// this.getToken()
		},
		onShow() {
			this.userInfo = uni.getStorageSync('userInfo');
			this.noCode = !uni.getStorageSync('token');
			if (uni.getStorageSync('token')) {
				this.getUserInfo();
			}
		}
	}
</script>

<style>
	page {
		background-color: #F6F6F6;
	}

	.page {
		padding-bottom: 50rpx;
	}

	.info_box {
		padding: 44rpx;
		background-color: #FFFFFF;
		border-radius: 16rpx;
		padding-bottom: 0;
		position: relative;
	}

	.info_box .first {
		height: 160rpx;
		line-height: 112rpx;
		padding-bottom: 40rpx;
	}

	.info_box .first .photo {
		width: 112rpx;
		height: 112rpx;
		border-radius: 50%;
		float: left;
		margin-right: 20rpx;

	}

	.info_box .first .fr {
		color: #999999;
		font-size: 22rpx;
	}

	.info_box .first .fr image {
		width: 12rpx;
		height: 20rpx;
		margin-left: 10rpx;
		vertical-align: middle;
	}



	.href_list {
		background-color: #FFFFFF;
	}

	.href_list .item {
		height: 100rpx;
		line-height: 100rpx;
		border-bottom: 1px solid #E2E4EA;
		font-size: 34rpx;
		position: relative;
		padding: 0 38rpx;
	}

	.href_list .item:last-child {
		border-bottom: none;
	}

	.href_list .item .icon {
		height: 40rpx;
		margin-right: 25rpx;
		position: relative;
		top: 6rpx;
	}

	.href_list .item .right {
		float: right;
		width: 12rpx;
		height: 20rpx;
		position: relative;
		top: 40rpx;
	}

	.href_list .kf_button {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		opacity: 0;
	}

	.login_btn {
		color: #333333;
		background-color: transparent;
		text-align: left;
		font-size: 40rpx;
		padding: 0;
		line-height: auto;
		display: inline-block;
		overflow: initial;
		padding: 0 50rpx;
	}

	.login_btn::after {
		border: none;
	}
	.modal{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0,0,0,.7);
		z-index: 10;
	}
	.modal image{
		display: block;
		height: 400rpx;
		width: 400rpx;
		position: absolute;
		top: 50%;
		margin-top: -200rpx;
		left: 200rpx;
	}
	.card{
		background-color: #FFFFFF;
	}
	.card .box{
		width: 700rpx;
		height: 120rpx;
		line-height: 120rpx;
		margin: 0 auto;
		background-color: #FFE6B5;
		border-radius: 16rpx 16rpx 0px 0px;
		color: #8F6D21;
		font-size: 34rpx;
	}
	.card .box image{
		width: 54rpx;
		height: 54rpx;
		vertical-align: middle;
		margin-left: 40rpx;
		margin-right: 24rpx;
		position: relative;
		top: -4rpx;
	}
	.card .box .btn{
		width: 148rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		color: #8F6D21;
		float: right;
		border: 2rpx solid #8F6D21;
		border-radius: 8rpx;
		margin-top: 30rpx;
		margin-right: 40rpx;
	}
</style>
